package com.lry.triTree;


import org.apache.lucene.util.RamUsageEstimator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author JiangJie
 * @create 2020-12-09 10:54
 */
public class Test {
    @org.junit.Test
    public void testTreeNode(){
        Node parent = new Node(1);

        Node line1 = new Node(2,parent);
        Node line2 = new Node(3,parent);
        Node line3 = new Node(4,parent);

        parent.line1 = line1;
        parent.line2 = line2;
        parent.line3 = line3;

        //计算指定对象本身在堆空间的大小，单位字节
        long usage = RamUsageEstimator.shallowSizeOf(parent);
        System.out.println(usage+" byte");
        double num = Math.pow(3,15);//1400百万用户
        System.out.println("用户 "+num);
        System.out.println(num*usage/1024/1024+" M");
    }

    @org.junit.Test
    public void testUserNode(){
        UserNode userNode = new UserNode(1,"1,2,3,4,5,6,7,8,9,10,11,12,13",12);
        long usage = RamUsageEstimator.shallowSizeOf(userNode);
        System.out.println(usage+" byte");
        double num = Math.pow(3,15);//1400百万用户
        System.out.println("用户 "+num);
        System.out.println(num*usage/1024/1024+" M");
    }


    public static void main(String[] args) {
        UserNode rootUserNode = new UserNode(1, null, null);
        List<UserNode> list =  initData();
        TriTree triTree = new TriTree();

        Node root = triTree.buildTree(rootUserNode,list);


        UserNode userNode = new UserNode(16,5);
        triTree.insert("",userNode);
        System.out.println(userNode);
    }

    private static List<UserNode> initData(){
        List<UserNode> list = new ArrayList<>();
        //数据必须根据path排序
        list.add(new UserNode(2, "1", 1));
        list.add(new UserNode(3, "1", 1));
        list.add(new UserNode(4, "1", 1));

        list.add(new UserNode(5, "1,2", 1));
        list.add(new UserNode(6, "1,2", 2));
        list.add(new UserNode(7, "1,2", 2));

        list.add(new UserNode(8, "1,3", 3));
        list.add(new UserNode(9, "1,3", 3));
        list.add(new UserNode(10, "1,3", 3));

        list.add(new UserNode(11, "1,4", 4));
        list.add(new UserNode(12, "1,4", 4));
        list.add(new UserNode(13, "1,4", 4));

        list.add(new UserNode(14, "1,2,5", 2));
        list.add(new UserNode(15, "1,2,5", 5));



        return list;
    }
}
